#include <iostream>
#include <vector>
#include <string>
using namespace std;

bool scanUnsignedInteger(const string &str,
                         int &idx) {
  int begin = idx;
  while (idx < str.size() && str[idx] >= '0' && str[idx] <= '9') {
    ++idx;
  }
  return idx > begin ? true : false;
}

bool scanSignedInteger(const string &str,
                       int &idx) {
  if (idx < str.size() && (str[idx] == '+' || str[idx] == '-')) {
    ++idx;
  }
  return scanUnsignedInteger(str, idx);
}

bool isNumeric(const string &str) {
  if (str.size() == 0) {
    return false;
  }
  int idx = 0;
  bool ret = scanSignedInteger(str, idx);
  if (idx < str.size() && str[idx] == '.') {
    ++idx;
    ret = scanUnsignedInteger(str, idx) || ret; // 一定是ret在后面
  }
  if (idx < str.size() && (str[idx] == 'e' || str[idx] == 'E')) {
    ++idx;
    ret = ret && scanSignedInteger(str, idx);
  }
  return ret && idx == str.size();
}

int main() {
  vector<string> vec_str = {"+100", "5e2", "-123", "3.1415", "-1E-16", "12e", "1a3.14", "1.2.3", "+-5", "12e+5.4", ".123", "123.123", "123.", ".e1"};
  cout << "The string is a number?" << endl;
  for (int i = 0; i < vec_str.size(); ++i) {
    cout << vec_str[i] << ": " << isNumeric(vec_str[i]) << endl;
  }
  return 0;
}
